<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>防抖</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color:skyblue;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        var el = document.getElementsByClassName("box")[0];

        var t = null;
        el.onmouseover = function(){
            clearTimeout(t);
            t = setTimeout(function(){
                console.log(1);
            },1000);
        }

        /*
        上面还算不上防抖， 而且还污染全局。
        防抖是初次触发时，不会被延迟。  防抖的使用场景比如 下拉刷新
        * */

    </script>
</body>
</html>
